package 华为OD机试B卷复用题.基础题;

import utils.MyUtil;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class HJ56_事件推送 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试B卷复用题/基础题/input/56.txt"));
        MyUtil.START();
        Solution(in);
        MyUtil.END();
    }

    // 简单，双指针
    static void Solution(Scanner in) {
        int R = 5;
        int[] A = {1, 5, 5, 10};
        int[] B = {1, 3, 8, 8, 20};
        int p1 = 0, p2 = 0;
        while (p1 < A.length && p2 < B.length) {
            int chazhi = B[p2] - A[p1];
            if (chazhi >= 0 && chazhi <= R) {
                System.out.println(A[p1] + " " + B[p2]);
                p1++;
                p2++;
            } else if (chazhi < 0) {
                p2++;
            } else if (chazhi > R) {
                p1++;
            }
        }
    }
}
